import { defineStore } from 'pinia'
import { useRequest } from '~/composables/useRequest'

export const useArticleStore = defineStore('articleStore', () => {
  const { requestGetNew, requestPost } = useRequest()
  const state = reactive({
    homeArticleList: [],
    articleCategories: [],
  })

  return {
    ...toRefs(state),
    async initHomeArticles() {
      const { data } = await requestGetNew('/app/news/homeArticles')
      state.homeArticleList = data ?? []
    },
    // 获取文章分类
    async initArticleCategory(categoryId?) {
      const data = await requestGetNew('/app/news/newCategories')
      state.articleCategories = data ?? []
    },
    // 获取文章列表
    async getArticlesByCategoryId(categoryId, num, size) {
      const data = await requestGetNew(`/app/news/newsByCategory/${num}/${size}`, { categoryId })
      return data ?? {}
    },
  }
})
